package org.linlinjava.litemall.wx.util;

import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 时间范围判断
 *
 * @author zhy
 * @date 2019-07-23 15:48
 **/
@Component
public class TimeJudge {
	public boolean isTimeRange()throws ParseException {
		SimpleDateFormat df = new SimpleDateFormat("HH:mm");
		Date now = null;
		Date begin = null;
		Date end = null;
		try {
			now = df.parse(df.format(new Date()));
			begin = df.parse("3:00");
			end = df.parse("22:30");
		}
		catch (ParseException e) {
			e.printStackTrace();
		}
		Calendar nowTime = Calendar.getInstance();
		nowTime.setTime(now);
		Calendar beginTime = Calendar.getInstance();
		beginTime.setTime(begin);
		Calendar endTime = Calendar.getInstance();
		endTime.setTime(end);
		if (nowTime.before(endTime) && nowTime.after(beginTime)) {
			return true;
		} else {
			return false;
		}
	}
}
